Add get_placeholder to handle automatic check constraint evaluation #125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As from django 4.1
CheckConstraint
are evaluated during theModel.full_clean
process using model data.As of now this does not work with netfields since the checker does not produce the right query (see https://github.com/sevdog/netfields-check-error for reference).
With a check constraint like the following:
the ORM produces the following query:
which raises an error on Postgresql since
Thus if this is called inside a transaction then any following query will fail since the transaction is not on a clean state and raising
Looking at similar issue on django (see https://code.djangoproject.com/ticket/34059) the solution seems to be adding a new method
Field.get_placeholder
which is used by ORM to insert values in this process.